path = require("path")
src_dir = ["models","controllers","services","lib"]

compile_files = () ->
  for d in src_dir
    expand: true
    flatten: false
    src: "#{d}/*.coffee"
    dest: "node_modules/gfportal/#{d}/"
    cwd: "./"
    ext: ".js"

watch_files = () ->
  for d in src_dir
    "#{d}/*.coffee"

console.log JSON.stringify compile_files()

module.exports = (grunt) ->
    grunt.initConfig(
        pkg: grunt.file.readJSON('package.json'),
        coffee:
          all:
            files: compile_files()
          compile:
            files:
              expand: true
              flatten: false
              src: ""
              dest: ""
              cwd: "./"
              ext: ".js"
        watch:
          compile:
            files: watch_files()
            tasks: ['coffee:compile']
            options:
              spawn: false
    )
    
    grunt.loadNpmTasks('grunt-contrib-coffee')
    grunt.loadNpmTasks('grunt-contrib-watch')
    grunt.registerTask('default',['coffee','watch'])

    grunt.event.on 'watch', (action, filepath)->
      grunt.config "coffee.compile.src", filepath
      grunt.config "coffee.compile.dest", ("./node_modules/gfportal/"+filepath).replace(".coffee",".js")
